package com.example.chengche_lol.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.example.chengche_lol.base.BaseVpAdapter;
import com.example.chengche_lol.beans.NewsTypeBean;
import com.example.chengche_lol.ui.news.NewsActivityFragment;
import com.example.chengche_lol.ui.news.NewsChannelFragment;
import com.example.chengche_lol.ui.news.NewsCloudFragment;
import com.example.chengche_lol.ui.news.MobilegameFragment;
import com.example.chengche_lol.ui.news.NewsArticleFragment;
import com.example.chengche_lol.ui.news.NewsMatchFragment;
import com.example.chengche_lol.ui.news.NewsRecommendFragment;
import com.example.chengche_lol.ui.news.NewsVideoFragment;

public class NewsVpAdapter extends BaseVpAdapter<NewsTypeBean> {

    public NewsVpAdapter(@NonNull FragmentManager fm) {
        super(fm);
    }
//每个tab的切换
    @Override
    protected Fragment createFragment(int position) {
        Fragment fragment = null;
        NewsTypeBean bean = getData(position);
        if (bean.getType() == NewsTypeBean.TYPE_ARTICLE) {
            fragment = new NewsArticleFragment();
        }
        if (bean.getType() == NewsTypeBean.TYPE_RECOMMEND) {
            fragment = new NewsRecommendFragment();
        }
        if (bean.getType() == NewsTypeBean.TYPE_MOBILEGAME) {
            fragment = new MobilegameFragment();
        }
        if (bean.getType() == NewsTypeBean.TYPE_CLOUD) {
            fragment = new NewsCloudFragment();
        }
        if (bean.getType() == NewsTypeBean.TYPE_GAMES) {
            fragment = new NewsMatchFragment();
        }
        if (bean.getType() == NewsTypeBean.TYPE_VIDEO) {
            fragment = new NewsVideoFragment();
        }
        if (bean.getType() == NewsTypeBean.TYPE_CHANNEL) {
            fragment = new NewsChannelFragment();
        }
        if (bean.getType() == NewsTypeBean.TYPE_ACTIVITY) {
            fragment = new NewsActivityFragment();
        }
        return fragment;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return getData(position).getTitle();
    }

}
